<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function Person(name, age) {
      this.name = name
      this.age = age

      // return {m: 1}
      return [1]
      // return () => {}
      // return 1
    }

    const p = new Person('A', 12)   // 内部: this.__proto__ = Person.prototype
    console.log(p)


    function newInstance(Type, ...args) {
      // 创建一个Object实例对象
      const obj = {}
      // 给对象添加__proto__属性, 值是Type.prototype
      obj.__proto__ = Type.prototype
      // 调用Type, 并指定this为新创建的对象
      const result = Type.call(obj, ...args)
      // 返回新创建对象或result对象
      return result instanceof Object ? result : obj
    }

    const p2 = newInstance(Person, "B", 13)
    console.log(p2)
  </script>
</body>
</html>